package cn.eaay.stock.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * 时间工具类
 */
public class DateUtil {

    public static final String FULL_TIME_SPLIT_PATTERN = "yyyy-MM-dd HH:mm:ss";

    /**
     * 将时间戳转为String
     *
     * @param time
     * @return
     */
    public static String formatFullTime(String time) {
        SimpleDateFormat formatter = new SimpleDateFormat(FULL_TIME_SPLIT_PATTERN);
        return formatter.format(new Date(Long.parseLong(time + "000")));
    }

    public static Date formatFullDate(String date) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return formatter.parse(date);
    }

    public static Date formatDateTime(String date) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat(FULL_TIME_SPLIT_PATTERN);
        return formatter.parse(date);
    }

    /**
     * 将时间戳转为Date
     *
     * @param time
     * @return
     */
    public static Date timeFullDate(String time) {
        return new Date(Long.parseLong(time + "000"));
    }

    public static String getDateFormat(Date date) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FULL_TIME_SPLIT_PATTERN, Locale.CHINA);
        return simpleDateFormat.format(date);
    }

    public static String getDateFormat(Date date, String dateFormatType) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatType, Locale.CHINA);
        return simpleDateFormat.format(date);
    }
}
